<template>
  <div class="global_order marginTop10">
    <div class="main_white padding10 paddingTop0">
      <div class="main_ti">
        <el-tabs v-model="activeName">
          <el-tab-pane :label="companyInfo.model == 3 ? '在线支付' : '银联支付'" name="0"></el-tab-pane>
          <el-tab-pane label="百度高德" name="1"></el-tab-pane>
          <el-tab-pane label="短信通知" name="2"></el-tab-pane>
          <el-tab-pane label="微信配置" name="3"></el-tab-pane>
          <el-tab-pane label="药残检测" name="4"></el-tab-pane>
          <el-tab-pane label="用友T+" name="5"></el-tab-pane>
          <el-tab-pane label="视频配置" name="6"></el-tab-pane>
        </el-tabs>
        <div class="mainua_form">
          <union-pay v-if="activeName == 0"></union-pay>
          <baidu-map v-if="activeName == 1" :form="baidmap_form" ref="baiduMap" @save="preservation"></baidu-map>
          <short-message v-if="activeName == 2" :form="shortMessage_form" ref="shortmessage"
            @save="preservation"></short-message>
          <we-chat v-if="activeName == 3" :form="wechat_form" ref="wechat" @save="preservation"></we-chat>
          <drug-check v-if="activeName == 4" :form="drug_form"></drug-check>
          <div v-if="activeName == 5">
            <t-plus v-if="activeName == 5" :form="tplus_form" ref="tplus" @save="preservation"></t-plus>
          </div>
          <ying-shi v-if="activeName == 6" :form="yingshi_form" ref="YingShi" @save="preservation"></ying-shi>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import BaiduMap from "@/views/global/third_part_modules/baiduMap.vue";
import ShortMessage from "@/views/global/third_part_modules/shortMessage.vue";
import UnionPay from "@/views/global/third_part_modules/unionPay.vue";
import WeChat from "@/views/global/third_part_modules/weChat.vue";
import DrugCheck from "@/views/global/third_part_modules/drugCheck.vue";
import TPlus from "@/views/global/third_part_modules/tplus.vue";
import YingShi from "@/views/global/third_part_modules/YingShi.vue";

import { setting_info, sms_info_stock } from "@/api/global/globalSystem";
import { setting_company } from "@/api/currency";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { mapGetters } from "vuex";
export default {
  components: {
    BaiduMap,
    ShortMessage,
    UnionPay,
    WeChat,
    DrugCheck,
    TPlus,
    YingShi
  },
  computed: {
    ...mapGetters(["companyInfo"])
  },
  data() {
    return {
      // 菜单切换
      activeName: "0",
      // 百度地图
      baidmap_form: {
        baidu_ak: "",
        baidu_service_id: "",
        amap_key: "",
        baidu_distinguis_api_key: "",
        baidu_distinguis_secret_key: ""
      },
      shortMessage_form: {
        sms_account: "", //短信账号
        sms_password: "",
        sms_template: "",
        sms_notice: "",
        sms_notice_number: "",
        sms_stock: "",
        send_message_order_delivery_to_driver_status: false,
        send_message_order_to_salesman_status: false,
        send_message_order_to_user_status: false,
        send_message_purchase_order_to_buyer_status: false,
        send_message_purchase_order_to_supplier_status: false
      },
      wechat_form: {
        wx_pic: "",
        wx_appId: "",
        wx_appSecret: "",
        mini_pic: "",
        mini_appId: "",
        mini_appSecret: "",
        share_title: "",
        share_img: "",
        share_describe: "",
        share_href: ""
      },
      drug_form: {
        drug_residue_automatic: ""
      },
      tplus_form: {
        tplus_appKey: "",
        tplus_appSecret: "",
        tplus_redirectUrl: "",
        tplus_keyt: ""
      },
      yingshi_form: {
        yingshi_key: "",
        yingshi_secret: "",
      }
    };
  },
  created() {
    this.setting_info();
    this.sms_info_stock();
    if (this.$route.params.type) {
      this.activeName = this.$route.params.type;
    }
    if (window.location.href) {
      let test = window.location.href;
      if (test.indexOf("?") != -1) {
        let str = test.substr(1);
        let strs = str.split("=");
        this.activeName = strs[1];
      }
    }
  },
  methods: {
    sms_info_stock() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          )
        },
        apiUrl().name
      );
      sms_info_stock(data).then(res => {
        if (res.errcode == 0) {
          this.shortMessage_form.sms_stock = res.data.balance;
        }
      });
    },
    // 基本信息
    setting_info() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          )
        },
        apiUrl().name
      );
      setting_info(data).then(res => {
        if (res.errcode == 0) {
          if (res.data.info) {
            // 百度地图
            this.baidmap_form.baidu_ak = res.data.info.baidu_ak;
            this.baidmap_form.baidu_service_id = res.data.info.baidu_service_id;
            this.baidmap_form.amap_key = res.data.info.amap_key;
            this.baidmap_form.baidu_distinguis_api_key =
              res.data.info.baidu_distinguis_api_key;
            this.baidmap_form.baidu_distinguis_secret_key =
              res.data.info.baidu_distinguis_secret_key;

            // 短信配置
            this.shortMessage_form.sms_account = res.data.info.sms_account;
            this.shortMessage_form.sms_password = res.data.info.sms_password;
            this.shortMessage_form.sms_template = res.data.info.sms_template;
            this.shortMessage_form.sms_notice =
              res.data.info.sms_notice == 0 ? false : true;
            this.shortMessage_form.sms_notice_number =
              res.data.info.sms_notice_number;

            this.shortMessage_form.send_message_order_delivery_to_driver_status =
              res.data.info.send_message_order_delivery_to_driver_status == 1
                ? true
                : false;
            this.shortMessage_form.send_message_order_to_salesman_status =
              res.data.info.send_message_order_to_salesman_status == 1
                ? true
                : false;
            this.shortMessage_form.send_message_order_to_user_status =
              res.data.info.send_message_order_to_user_status == 1 ? true : 0;
            this.shortMessage_form.send_message_purchase_order_to_buyer_status =
              res.data.info.send_message_purchase_order_to_buyer_status == 1
                ? true
                : false;
            this.shortMessage_form.send_message_purchase_order_to_supplier_status =
              res.data.info.send_message_purchase_order_to_supplier_status == 1
                ? true
                : false;

            //微信配置
            this.wechat_form.wx_pic = res.data.info.wx_pic;
            this.wechat_form.wx_appId = res.data.info.wx_appId;
            this.wechat_form.wx_appSecret = res.data.info.wx_appSecret;
            this.wechat_form.mini_pic = res.data.info.mini_pic;
            this.wechat_form.mini_appId = res.data.info.mini_appId;
            this.wechat_form.mini_appSecret = res.data.info.mini_appSecret;
            this.wechat_form.share_title = res.data.info.share_title;
            this.wechat_form.share_img = res.data.info.share_img;
            this.wechat_form.share_describe = res.data.info.share_describe;
            this.wechat_form.share_href = res.data.info.share_href;
            // 药残配置
            this.drug_form.drug_residue_automatic =
              res.data.info.drug_residue_automatic;
            this.drug_form.offical_seal_switch =
              res.data.info.offical_seal_switch;
            // 用友配置
            this.tplus_form.tplus_appKey = res.data.info.tplus_appKey;
            this.tplus_form.tplus_appSecret = res.data.info.tplus_appSecret;
            this.tplus_form.tplus_redirectUrl = res.data.info.tplus_redirectUrl;
            this.tplus_form.tplus_keyt = res.data.info.tplus_keyt;

            this.yingshi_form.yingshi_key = res.data.info.yingshi_key;
            this.yingshi_form.yingshi_secret = res.data.info.yingshi_secret;
          }
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 保存
    preservation(params) {
      let form = params.data;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          )
        },
        apiUrl().name,
        form
      );
      return new Promise(resolve => {
        setting_company(data).then(res => {
          if (res.errcode == 0) {
            this.$message({
              message: "保存成功",
              type: "success"
            });
            resolve(res);
          } else {
            this.$message.error(res.errmsg);
          }
        });
      });
    },
    getQueryString() { }
  }
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.global_order {
  margin: 0 15px 0 15px;

  .mainua_form {
    .mainua_an {
      /deep/.el-form-item__content {
        margin-left: 0px !important;
      }

      .reset {
        background: $subActive;
        color: $menuText;
        border-color: $subActive;

        &:hover,
        &:focus {
          border-color: $menuActiveText;
          color: $menuActiveText;
        }
      }
    }
  }
}
</style>
